package com.qf.order.service.impl;

import com.qf.order.client.StockClient;
import com.qf.order.mapper.OrderMapper;
import com.qf.order.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper orderMapper;

    @Autowired
    private StockClient stockClient;

    @Override
    @GlobalTransactional
    public void create() {
        //1. 减库存
        stockClient.decrement();

        int i = 1 / 0;

        //2. 创建订单
        orderMapper.create();
    }
}
